

package MaintMenu.SyncInventoryToCat;

import javax.swing.*;
import java.sql.*;

public class UpdateTblinventoryPLfrom6Cats
{
    public UpdateTblinventoryPLfrom6Cats()

    {
        int x=0;
        int y=0;
        int cc=0;
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String dataSourceName = "dbLI";
            String dbURL = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName).toString();
            Connection conli = DriverManager.getConnection(dbURL, "", "");


            String st[] = new String[12];
            st[0] = ("UPDATE tblinventory AS a INNER JOIN tblbcn AS b ON a.[Part#] = b.[Part#] SET a.partslink = b.partlink;");

            st[1] = ("UPDATE tblinventory AS a INNER JOIN tblmrn AS b ON a.[Part#] = b.[Part#] SET a.partslink = b.partlink;");

            st[2] = ("UPDATE tblinventory AS a INNER JOIN tblotn AS b ON a.[Part#] = b.[Part#] SET a.partslink = b.partlink;");

            st[3] = ("UPDATE tblinventory AS a INNER JOIN tblltn AS b ON a.[Part#] = b.[Part#] SET a.partslink = b.partlink;");

            st[4] = ("UPDATE tblinventory AS a INNER JOIN tblcln AS b ON a.[Part#] = b.[Part#] SET a.partslink = b.partlink;");

            st[5] = ("UPDATE tblinventory AS a INNER JOIN tblhfn AS b ON a.[Part#] = b.[Part#] SET a.partslink = b.partlink;");

            //update mast files PL with tblinventory pl#

            st[6] = ("UPDATE bcmast AS a INNER JOIN tblinventory AS b ON a.item_no = b.[Part#] SET a.partlink = b.partslink;");
            st[7] = ("UPDATE hfmast AS a INNER JOIN tblinventory AS b ON a.item_no = b.[Part#] SET a.partlink = b.partslink;");
            st[8] = ("UPDATE coolngm AS a INNER JOIN tblinventory AS b ON a.item_no = b.[Part#] SET a.partlink = b.partslink;");
            st[9] = ("UPDATE lt_mast1 AS a INNER JOIN tblinventory AS b ON a.item_no = b.[Part#] SET a.partlink = b.partslink;");
            st[10] = ("UPDATE mirrorm1 AS a INNER JOIN tblinventory AS b ON a.item_no = b.[Part#] SET a.partlink = b.partslink;");
            st[11] = ("UPDATE otmast AS a INNER JOIN tblinventory AS b ON a.item_no = b.[Part#] SET a.partlink = b.partslink;");

//            st[7] = ("UPDATE tblinventory AS a INNER JOIN tblmrn AS b ON a.[Part#] = b.[Part#] SET a.partslink = b.partlink;");
//
//            st[8] = ("UPDATE tblinventory AS a INNER JOIN tblotn AS b ON a.[Part#] = b.[Part#] SET a.partslink = b.partlink;");
//
//            st[9] = ("UPDATE tblinventory AS a INNER JOIN tblltn AS b ON a.[Part#] = b.[Part#] SET a.partslink = b.partlink;");
//
//            st[10] = ("UPDATE tblinventory AS a INNER JOIN tblcln AS b ON a.[Part#] = b.[Part#] SET a.partslink = b.partlink;");
//
//            st[11] = ("UPDATE tblinventory AS a INNER JOIN tblhfn AS b ON a.[Part#] = b.[Part#] SET a.partslink = b.partlink;");

            for (x=0; x<st.length;x++){
                Statement stli = conli.createStatement();

                try {

//                    System.out.print("Script :" + x);
                    int rowsupdated = stli.executeUpdate(st[x]);
//                    System.out.print("TRU :"+rowsupdated+" ... \t");
                    cc++;
                    if (cc==4){
//                        System.out.println("");
                        cc=0;
                    }
                }catch (SQLException r){}
            }

                    //JOptionPane.showOptionDialog(null, "Statement : " + st[x] + "\n\nTotal record Updated : " + rowsupdated, "Update Complete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[]{}, null);





            //***** Cleaup tblinventory PL. remove character after 9 character of Partlink standard.





        }
        catch(Exception e)
        {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, e);
        }
    }
}
